#ifndef POWERRAMPPARAMS_H
#define POWERRAMPPARAMS_H

#include <QSettings>
#include "jsonconvert.h"

class PowerRampParams : public JsonConvert
{
public:
    PowerRampParams(){}

    bool enable()
    {
        return mEnable;
    }

    void setEnable(bool enable)
    {
        mEnable = enable;
    }

    int startLevel()
    {
        return mStartLevel;
    }

    void setStartLevel(int startLevel)
    {
        mStartLevel = startLevel;
    }

    int endLevel()
    {
        return mEndLevel;
    }

    void setEndLevel(int endLevel)
    {
        mEndLevel = endLevel;
    }

    double startLength()
    {
        return mStartLength;
    }

    void setStartLength(double startLength)
    {
        mStartLength = startLength;
    }

    double endLength()
    {
        return mEndLength;
    }

    void setEndLength(double endLength)
    {
        mEndLength = endLength;
    }

    bool externalRamp()
    {
        return mExternalRamp;
    }

    void setExternalRamp(bool externalRamp)
    {
        mExternalRamp = externalRamp;
    }

    void readFromFile()
    {
        QSettings settings("GlobalLaser.ini", QSettings::IniFormat);
        settings.beginGroup("Power_Ramp");
        this->mEnable = settings.value("mEnable", false).toBool();
        this->mStartLevel = settings.value("mStartLevel", 100).toInt();
        this->mEndLevel = settings.value("mEndLevel", 100).toInt();
        this->mStartLength = settings.value("mStartLength", 0).toDouble();
        this->mEndLength = settings.value("mEndLength", 0).toDouble();
        this->mExternalRamp = settings.value("mExternalRamp").toBool();
        settings.endGroup();
    }

    void writeToFile()
    {
        QSettings settings("GlobalLaser.ini", QSettings::IniFormat);
        settings.beginGroup("Power_Ramp");
        settings.setValue("mEnable",  mEnable);
        settings.setValue("mStartLevel",  mStartLevel);
        settings.setValue("mEndLevel",  mEndLevel);
        settings.setValue("mStartLength",  mStartLength);
        settings.setValue("mEndLength",  mEndLength);
        settings.setValue("mExternalRamp",  mExternalRamp);
        settings.endGroup();
    }

    QJsonObject toJsonObj() const
    {
        QJsonObject obj;
        obj["mEnable"] = mEnable;
        obj["mStartLevel"] = mStartLevel;
        obj["mEndLevel"] = mEndLevel;
        obj["mStartLength"] = mStartLength;
        obj["mEndLength"] = mEndLength;
        obj["mExternalRamp"] = mExternalRamp;
        return obj;
    }

    void fromJsonObj(const QJsonObject& obj)
    {
        mEnable = obj["mEnable"].toBool();
        mStartLevel = obj["mStartLevel"].toInt();
        mEndLevel = obj["mEndLevel"].toInt();
        mStartLength = obj["mStartLength"].toDouble();
        mEndLength = obj["mEndLength"].toDouble();
        mExternalRamp = obj["mExternalRamp"].toBool();
    }

    bool operator ==(const PowerRampParams& param){
        bool rel = true;
        rel &= (this->mEnable == param.mEnable);
        rel &= (this->mStartLevel == param.mStartLevel);
        rel &= (this->mEndLevel == param.mEndLevel);
        rel &= (this->mStartLength == param.mStartLength);
        rel &= (this->mEndLength == param.mEndLength);
        rel &= (this->mExternalRamp == param.mExternalRamp);
        return rel;
    }

    void operator =(const PowerRampParams& param){
        this->mEnable = param.mEnable;
        this->mStartLevel = param.mStartLevel;
        this->mEndLevel = param.mEndLevel;
        this->mStartLength = param.mStartLength;
        this->mEndLength = param.mEndLength;
        this->mExternalRamp = param.mExternalRamp;
    }
private:
    bool mEnable = false;
    int mStartLevel = 0;
    int mEndLevel = 0;
    double mStartLength = 0;
    double mEndLength = 0;
    bool mExternalRamp = false;
};

#endif // POWERRAMPPARAMS_H
